﻿Imports ACompany.OrderProcessing.Model

Public Class OrderRepository
    Inherits BaseRepository(Of Order)
    Implements IOrderRepository

    Public Function FindAllOrdersContainingProductBy(ByVal ProductId As Guid) As System.Collections.Generic.IList(Of Model.Order) Implements Model.IOrderRepository.FindAllOrdersContainingProductBy

        ' HQL
        Return SessionFactory.GetCurrentSession.CreateQuery( _
            "select o from Order o, elements(o.Items) i where i.Product.Id = :ProductID") _
            .SetString("ProductID", ProductId.ToString) _
            .List(Of Order)()

        ' OR

        ' Criteria API

        'Return SessionFactory.GetCurrentSession.CreateCriteria(GetType(Order)) _
        '    .CreateCriteria("Items") _
        '    .Add(NHibernate.Criterion.Expression.Eq("Product.Id", ProductId)) _
        '    .List(Of Order)()

    End Function
End Class
